package com.db.collections.arraycopy;

public class ArrayCoppyAgainstForCycle {
   private static final int warmUp = 10;
    public static void main(String[] args) {
        int[] sizes = {1000, 100000, 10000000};
        for(int i : sizes){
            computeCoef(i);
        }
    }

    private static void computeCoef(int size) {
        int[] arr = new int[size];

        long start, finish;
        long systemTime, forTime;
        start = finish = 0;


        for (int i = 0; i < warmUp; i++) {
            int[] forArr = new int[size];
            start = System.nanoTime();
            for (int j = 0; j < forArr.length; j++) {
                forArr[j] = arr[j];
            }
            finish = System.nanoTime();
        }
        forTime = (finish - start);
        System.out.println("forTime " + forTime);

        for (int i = 0; i < warmUp; i++) {
            int[] systemArray = new int[size];
            start = System.nanoTime();
            System.arraycopy(arr, 0, systemArray, 0, arr.length);
            finish = System.nanoTime();
        }
        systemTime = (finish - start);
        System.out.println("systemTime " + systemTime);


        System.out.println("size: " + size + " coef: " + 1. * forTime / systemTime);
    }
}
/*
forTime 20135
systemTime 411
size: 1000 coef: 48.990267639902676
forTime 2050910
systemTime 48899
size: 100000 coef: 41.94175750015338
forTime 8452247
systemTime 7926678
size: 10000000 coef: 1.0663038160500526
* */